import mysql from "mysql2/promise";
import config from "../config.json";

const connection = mysql.createPool({
  host: config.mysql_host,
  port: config.mysql_port,
  user: config.mysql_user,
  password: config.mysql_password,
  database: config.mysql_database,
  connectionLimit: 10,
  maxIdle: 10, // 最大空闲连接数，默认等于 `connectionLimit`
  idleTimeout: 60000, // 空闲连接超时，以毫秒为单位，默认值为 60000 ms
  queueLimit: 0,
  enableKeepAlive: true,
  keepAliveInitialDelay: 0,
});

export const query = async (sql: string, values?: any[]) => {
  const [results] = await connection.execute(sql, values);
  return results;
};
